package com.wangrui.us3.s3;

import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Configuration;
import software.amazon.awssdk.services.s3.presigner.S3Presigner;

import java.net.URI;

public class S3Util {
    public static S3Presigner getPreDesigner(){
        // S3 配置
        String endpoint = "http://s3-cn-wlcb.ufileos.com";
        AwsCredentials credentials = new AwsCredentials() {
            @Override
            public String accessKeyId() {
                return "TOKEN_67b1ecee-13ed-4148-8639-af3575679bdb"; // 访问密钥
            }

            @Override
            public String secretAccessKey() {
                return "cace2482-bbbc-4502-a233-d00525b1ebf8"; // 密钥
            }
        };

        StaticCredentialsProvider credentialsProvider = StaticCredentialsProvider.create(credentials);

        // 创建S3配置 - 启用路径风格
        S3Configuration s3Configuration = S3Configuration.builder()
                .pathStyleAccessEnabled(true)
                .build();
        return S3Presigner.builder()
                .region(Region.AP_NORTHEAST_1)
                .credentialsProvider(credentialsProvider)
                .endpointOverride(URI.create(endpoint))
                .serviceConfiguration(s3Configuration)
                .build();
    }
}
